#include "Projectile.h"
#include "MemoryStream.h"
#include "GameManager.h"

CProjectile::CProjectile(void)
{
}

CProjectile::~CProjectile(void)
{
	
}
void CProjectile::passTime(f32 delta) {

}
bool CProjectile::collisionCallback(CSceneObject *obj) {
	CShip *shipPtr;
	
	DEBUG_PRINT("Projectile collision - ");
	DEBUG_PRINT("ID:%d,Type:%d -> ID:%d,Type:%d\n", this->getID(), this->getType(), 
													obj->getID(), obj->getType());
	
	// big boom! Did we hit a ship?
	if(obj->getType() == E_GAMEOBJECT_TYPE::Ship) {
		SArmor dmg;
		shipPtr = (CShip *)obj;	
		
		dmg = SArmor(0, this->getBaseDamage(), this->getBaseDamage(), this->getBaseDamage(), this->getBaseDamage());
		
		DEBUG_PRINT("\tApplying damage to ship - \n");
		if(shipPtr->applyDamage(dmg)) {
			// ship was destroyed
		} else {
			// not destroyed
		}
	}

	// queue ourselves for deleting
	this->misDestroyed = true;

	return false;
}

CProjectile *CProjectile::copy(void) {
	CProjectile *ptr = new CProjectile();

	this->copy(ptr);
	
	return ptr;
}
void CProjectile::copy(CProjectile *ptr) {
	ptr->setXmlID(this->getXmlID());
	ptr->setName(this->getName());
	ptr->setClass(this->getClass());
	ptr->setMass(this->getMass());

	ptr->setMaxNormalAcceleration(this->getMaxNormalAcceleration());
	ptr->setMaxHyperAcceleration(this->getMaxHyperAcceleration());
	ptr->setMeshPath(this->getMeshPath());

	ptr->setMesh(CGameManager::getInstance()->getSceneManager()->getMesh(this->getMeshPath()));
	ptr->setSceneNode(CGameManager::getInstance()->getSceneManager()->addMeshSceneNode(ptr->getMesh()));

	ptr->setPhysxMesh(CGameManager::getInstance()->getPhysxManager()->createConvexMesh(ptr->getMesh()->getMeshBuffer(0), vector3df(1,1,1)));
	ptr->setPhysxObject(CGameManager::getInstance()->getPhysxManager()->createConvexMeshObject(ptr->getPhysxMesh(), vector3df(0,0,0)));
	ptr->getPhysxObject()->setUserData(ptr);

	ptr->setPosition(this->getPosition());
	ptr->setAcceleration(this->getAcceleration());
	ptr->setVelocity(this->getVelocity());
	ptr->setStandoffRange(this->getStandoffRange());
	ptr->setBaseDamage(this->getBaseDamage());
}
